<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>专利管理系统 - 注册</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">

    <!-- Tailwind配置 -->
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#165DFF',
                        secondary: '#0A2463',
                        accent: '#3E92CC',
                        neutral: '#F5F7FA',
                        'neutral-dark': '#1E293B'
                    },
                    fontFamily: {
                        inter: ['Inter', 'sans-serif'],
                    },
                }
            }
        }
    </script>

    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
            .register-shadow {
                box-shadow: 0 10px 25px -5px rgba(22, 93, 255, 0.1), 0 8px 10px -6px rgba(22, 93, 255, 0.1);
            }
            .bg-gradient-register {
                background: linear-gradient(135deg, #165DFF 0%, #0A2463 100%);
            }
            .form-input-focus {
                @apply focus:border-primary focus:ring focus:ring-primary/30 transition-all duration-200;
            }
        }
    </style>
</head>
<body class="font-inter bg-neutral min-h-screen flex items-center justify-center p-4">
<!-- 背景装饰 -->
<div class="fixed inset-0 bg-gradient-to-br from-primary/5 to-secondary/5 -z-10"></div>

<div class="w-full max-w-md">
    <!-- 注册卡片 -->
    <div class="bg-white rounded-2xl shadow-xl overflow-hidden register-shadow transition-all duration-300 hover:shadow-2xl">
        <!-- 卡片顶部 -->
        <div class="bg-gradient-register p-8 text-white text-center">
            <h2 class="text-2xl font-bold mb-2">专利管理系统</h2>
            <p class="text-white/80">创建您的账户</p>
        </div>

        <!-- 注册表单 -->
        <div class="p-8">
            <form id="registerForm" action="#" th:action="@{/register}" th:method="post" class="space-y-6">
                <!-- CSRF令牌 -->
                <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}">

                <!-- 姓名 -->
                <div class="space-y-2">
                    <label for="fullname" class="block text-sm font-medium text-gray-700">姓名</label>
                    <div class="relative">
                        <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                            <i class="fa fa-user text-gray-400"></i>
                        </div>
                        <input type="text" id="fullname" name="fullname" class="pl-10 block w-full rounded-lg border-gray-300 shadow-sm form-input-focus" placeholder="请输入您的姓名" required>
                    </div>
                </div>

                <!-- 用户名 -->
                <div class="space-y-2">
                    <label for="username" class="block text-sm font-medium text-gray-700">用户名</label>
                    <div class="relative">
                        <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                            <i class="fa fa-user-circle text-gray-400"></i>
                        </div>
                        <input type="text" id="username" name="username" class="pl-10 block w-full rounded-lg border-gray-300 shadow-sm form-input-focus" placeholder="请输入用户名" required>
                        <div class="hidden absolute right-3 top-3 text-green-500" id="username-available">
                            <i class="fa fa-check-circle"></i>
                        </div>
                        <div class="hidden absolute right-3 top-3 text-red-500" id="username-unavailable">
                            <i class="fa fa-exclamation-circle"></i>
                        </div>
                    </div>
                    <p class="text-xs text-gray-500">用户名长度应为4-20个字符，只能包含字母、数字和下划线</p>
                </div>

                <!-- 邮箱 -->
                <div class="space-y-2">
                    <label for="email" class="block text-sm font-medium text-gray-700">邮箱</label>
                    <div class="relative">
                        <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                            <i class="fa fa-envelope text-gray-400"></i>
                        </div>
                        <input type="email" id="email" name="email" class="pl-10 block w-full rounded-lg border-gray-300 shadow-sm form-input-focus" placeholder="请输入您的邮箱" required>
                    </div>
                </div>

                <!-- 密码 -->
                <div class="space-y-2">
                    <label for="password" class="block text-sm font-medium text-gray-700">密码</label>
                    <div class="relative">
                        <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                            <i class="fa fa-lock text-gray-400"></i>
                        </div>
                        <input type="password" id="password" name="password" class="pl-10 block w-full rounded-lg border-gray-300 shadow-sm form-input-focus" placeholder="请输入密码" required>
                        <button type="button" id="togglePassword" class="absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600">
                            <i class="fa fa-eye-slash"></i>
                        </button>
                    </div>
                    <p class="text-xs text-gray-500">密码长度应为8-20个字符，包含大小写字母、数字和特殊字符</p>
                </div>

                <!-- 确认密码 -->
                <div class="space-y-2">
                    <label for="confirm-password" class="block text-sm font-medium text-gray-700">确认密码</label>
                    <div class="relative">
                        <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                            <i class="fa fa-lock text-gray-400"></i>
                        </div>
                        <input type="password" id="confirm-password" name="confirm-password" class="pl-10 block w-full rounded-lg border-gray-300 shadow-sm form-input-focus" placeholder="请再次输入密码" required>
                    </div>
                </div>

                <!-- 手机号码 -->
                <div class="space-y-2">
                    <label for="phone" class="block text-sm font-medium text-gray-700">手机号码</label>
                    <div class="relative">
                        <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                            <i class="fa fa-phone text-gray-400"></i>
                        </div>
                        <input type="tel" id="phone" name="phone" class="pl-10 block w-full rounded-lg border-gray-300 shadow-sm form-input-focus" placeholder="请输入手机号码">
                    </div>
                </div>

                <!-- 同意条款 -->
                <div class="flex items-start">
                    <div class="flex items-center h-5">
                        <input id="terms" name="terms" type="checkbox" class="h-4 w-4 text-primary focus:ring-primary/30 border-gray-300 rounded" required>
                    </div>
                    <div class="ml-3 text-sm">
                        <label for="terms" class="text-gray-600">我已阅读并同意<a href="#" class="font-medium text-primary hover:text-primary/80">服务条款</a>和<a href="#" class="font-medium text-primary hover:text-primary/80">隐私政策</a></label>
                    </div>
                </div>

                <!-- 注册按钮 -->
                <div>
                    <button type="submit" class="w-full bg-primary hover:bg-primary/90 text-white font-medium py-3 px-4 rounded-lg shadow-md hover:shadow-lg transition-all duration-200 transform hover:-translate-y-0.5">
                        <i class="fa fa-user-plus mr-2"></i>注册
                    </button>
                </div>

                <!-- 分隔线 -->
                <div class="relative">
                    <div class="absolute inset-0 flex items-center">
                        <div class="w-full border-t border-gray-200"></div>
                    </div>
                    <div class="relative flex justify-center text-sm">
                        <span class="px-2 bg-white text-gray-500">或者</span>
                    </div>
                </div>

                <!-- 登录链接 -->
                <div class="text-center">
                    <p class="text-sm text-gray-600">
                        已有账户? <a href="#" id="login-link" class="font-medium text-primary hover:text-primary/80 transition-colors">立即登录</a>
                    </p>
                </div>
            </form>

            <!-- 注册成功消息 - 默认隐藏 -->
            <div id="register-success" class="hidden mt-6 p-4 bg-green-50 border border-green-200 rounded-lg text-sm text-green-700">
                <i class="fa fa-check-circle mr-2"></i> 注册成功！正在跳转至登录页面...
            </div>
        </div>
    </div>

    <!-- 页脚 -->
    <div class="mt-6 text-center text-sm text-gray-500">
        <p>© 2023 专利管理系统. 保留所有权利.</p>
    </div>
</div>

<!-- JavaScript -->
<script>
    // 切换密码可见性
    const togglePassword = document.getElementById('togglePassword');
    const passwordInput = document.getElementById('password');

    togglePassword.addEventListener('click', function() {
        const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
        passwordInput.setAttribute('type', type);

        // 切换图标
        this.querySelector('i').classList.toggle('fa-eye');
        this.querySelector('i').classList.toggle('fa-eye-slash');
    });

    // 用户名验证（示例，实际应用中应通过AJAX验证）
    const usernameInput = document.getElementById('username');
    const usernameAvailable = document.getElementById('username-available');
    const usernameUnavailable = document.getElementById('username-unavailable');

    usernameInput.addEventListener('input', function() {
        const username = this.value.trim();
        const regex = /^[a-zA-Z0-9_]{4,20}$/;

        // 简单验证用户名格式
        if (regex.test(username)) {
            // 模拟AJAX请求检查用户名可用性
            setTimeout(() => {
                // 这里应该是实际的AJAX请求
                // 示例：假设用户名"admin"和"test"已被使用
                if (username === "admin" || username === "test") {
                    usernameAvailable.classList.add('hidden');
                    usernameUnavailable.classList.remove('hidden');
                } else {
                    usernameAvailable.classList.remove('hidden');
                    usernameUnavailable.classList.add('hidden');
                }
            }, 500);
        } else {
            usernameAvailable.classList.add('hidden');
            usernameUnavailable.classList.add('hidden');
        }
    });

    // 密码匹配验证
    const confirmPasswordInput = document.getElementById('confirm-password');

    confirmPasswordInput.addEventListener('input', function() {
        const password = passwordInput.value;
        const confirmPassword = this.value;

        if (password !== confirmPassword) {
            this.classList.add('border-red-500');
            this.classList.remove('border-gray-300');
        } else {
            this.classList.remove('border-red-500');
            this.classList.add('border-gray-300');
        }
    });

    // 表单提交处理
    const registerForm = document.getElementById('registerForm');

    registerForm.addEventListener('submit', function(e) {
        e.preventDefault();

        // 显示加载状态
        const submitButton = this.querySelector('button[type="submit"]');
        submitButton.disabled = true;
        submitButton.innerHTML = '<i class="fa fa-spinner fa-spin mr-2"></i>注册中...';

        // 模拟表单提交
        setTimeout(() => {
            // 隐藏表单，显示成功消息
            this.classList.add('hidden');
            document.getElementById('register-success').classList.remove('hidden');

            // 3秒后跳转到登录页面
            setTimeout(() => {
                window.location.href = "/login"; // 替换为实际的登录页面URL
            }, 3000);
        }, 1500);
    });

    // 跳转到登录页面
    document.getElementById('login-link').addEventListener('click', function(e) {
        e.preventDefault();
        window.location.href = "/login"; // 替换为实际的登录页面URL
    });
</script>
</body>
</html>